<?php

/**
 * Created by PhpStorm.
 * User: Vova
 * Date: 8/30/14
 * Time: 5:17 PM
 */
class Login
{

    private $is_succesful;
    private $sql_login_host;
    private $sql_login_user;
    private $sql_login_pass;
    private $sql_login_db;

    private $con;
    function __construct() {
        $this->is_succesful = false;
        $this->sql_login_host = "localhost";
        $this->sql_login_user = "root";
        $this->sql_login_pass = "";
        $this->sql_login_db = "door_market";
        $this->con = mysqli_connect($this->sql_login_host, $this->sql_login_user, $this->sql_login_pass, $this->sql_login_db) or die("Some error occurred during connection " . mysqli_error($con));
    }


    public function login_attemp($user_name,$user_pass){
        $sql = "INSERT INTO SYSTEM_USER(user_name,user_pass) values('" . $user_name . "','" . md5($user_pass) . "')";
        $query = mysqli_query($this->con, $sql);

    }
    public function login($user_name,$user_pass){
        $user_name=mysqli_real_escape_string($this->con,$user_name);
        $user_pass=mysqli_real_escape_string($this->con,$user_pass);

        $sql="SELECT id FROM system_user WHERE user_name='$user_name' and user_pass='".md5($user_pass)."'";
        $result=mysqli_query($this->con,$sql);
        $count=mysqli_num_rows($result);
        if($count>0){
            return 1;
        }
        return 0;
    }

} 